package com.yidu.BusinessParament.controller;


import com.yidu.BusinessParament.entity.Broker2;
import com.yidu.BusinessParament.service.BrokerService;
import com.yidu.BusinessParament.util.IdUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @券商 Controller类
 * @version 1.0
 * @auther 林肯
 * @date 2022/12/8 -18:12
 */
@RestController
public class BrokerController {
    @Resource
    private BrokerService brokerService;

    /**
     * 查询数据
     * @param page 页码
     * @param limit 每页显示的条数
     * @param broker2 券商设置
     * @return
     */
    @RequestMapping("/selectBroker")
    public Map selectBroker(int page, int limit, Broker2 broker2){
        //查询加分页
        List<Broker2> brokersList = brokerService.selectBroker(page,limit,broker2);
        //查行数
        int count = brokerService.selectCount(broker2);
        System.out.println("行数"+count);
        //创建Map对象
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",brokersList);
        //返回值
        return map;
    }

    /**
     * 添加数据
     * @param broker2 券商设置
     * @return
     */
    @RequestMapping("/insertBroker")
    public int insertBroker(Broker2 broker2){
        System.out.println("进来了新增的方法");
        //得到最大的ID
        String maxId = brokerService.selectMaxId();
        //得到工具类
        IdUtil idUtil=new IdUtil();
        //得到工具类id的方法
        String id = idUtil.createID(maxId);
        System.out.println("新ID为"+id);
        broker2.setBrokerId(id);//设置券商ID
        //调用券商新增的方法
        int i = brokerService.insertBroker(broker2);
        //返回值
        return i;
    }

    /**
     * 删除数据
     * @param brokerId 券商编号
     * @return
     */
    @RequestMapping("/deleteBroker")
    public int deleteBroker(String brokerId){
        System.out.println("进来了删除方法!"+brokerId);
        int i = brokerService.deleteBroker(brokerId);
        if (i>0){
            System.out.println("删除成功!");
        } else {
            System.out.println("删除失败!");
        }
        return i;
    }

    /**
     * 修改数据
     * @param broker2 券商设置
     * @return
     */
    @RequestMapping("/updateBroker")
    public int updateBroker(Broker2 broker2){
        System.out.println("进来了修改方法!"+broker2);
        int i = brokerService.updateBroker(broker2);
        if (i>0){
            System.out.println("修改成功!");
        } else {
            System.out.println("修改失败!");
        }
        return i;
    }
}
